home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Book Chapters
/
13 - PowerPC
/
Optimize 1
/
Main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-05
|
4KB
|
174 lines
/*********************/
/* MAIN.C */
/*********************/
//
// This file contains all of the initialization and
// setup code needed to do the screen blit.
//
/****************************/
/* EXTERNALS */
/****************************/
#include <qdoffscreen.h>
/****************************/
/* PROTOTYPES */
/****************************/
static void ToolBoxInit(void);
static void HideMenuBar(void);
static void InitScreen(void);
static void InitDrawBuffer(void);
static void ShowMenuBar(void);
void main(void);
void ProfileIt(void);
/****************************/
/* CONSTANTS */
/****************************/
/****************************/
/* VARIABLES */
/****************************/
Ptr gScreenAddr,gDrawBufferPtr;
long gScreenRowBytes;
short gOldMBarHeight;
RgnHandle gMBarRgn;
/************* TOOLBOX INIT ***************/
//
// Initialize toolbox stuff.
//
static void ToolBoxInit(void)
{
MaxApplZone();
InitGraf(&qd.thePort);
FlushEvents ( everyEvent, 0);
InitFonts();
InitWindows();
InitDialogs(nil);
InitCursor();
InitMenus();
TEInit();
}
/**************** HIDE MENU BAR *******************/
//
// Hides the menu bar
//
static void HideMenuBar(void)
{
Rect mBarRect;
/* GET RID OF THE MENU BAR */
gOldMBarHeight = GetMBarHeight();
LMSetMBarHeight(0); // make the Menu Bar's height zero
SetRect(&mBarRect, qd.screenBits.bounds.left, qd.screenBits.bounds.top,
qd.screenBits.bounds.right, qd.screenBits.bounds.top + gOldMBarHeight);
gMBarRgn = NewRgn();
RectRgn(gMBarRgn, &mBarRect);
UnionRgn(LMGetGrayRgn(), gMBarRgn, LMGetGrayRgn()); // tell the desktop it covers the menu bar
PaintOne(nil, gMBarRgn); // redraw desktop
}
/******************** SHOW MENU BAR ******************/
//
// Restores the menu bar when we are done
//
static void ShowMenuBar(void)
{
LMSetMBarHeight(gOldMBarHeight); // make the menu bar's height normal
DiffRgn(LMGetGrayRgn(), gMBarRgn, LMGetGrayRgn()); // remove the menu bar from the desktop
DisposeRgn(gMBarRgn);
}
/******************* INIT SCREEN ***********************/
//
// Prepares screen for full-screen drawing.
// Hides the menu bar, then creates a giant
// window to cover the entire desktop.
//
static void InitScreen(void)
{
Rect screenRect;
GDHandle mainScreen;
PixMapHandle mainScreenPixMap;
WindowPtr bigWindow;
HideMenuBar(); // hide the menu bar
/* GET ADDR & ROWBYTES */
mainScreen = GetMainDevice(); // get screen device
mainScreenPixMap = (**mainScreen).gdPMap; // get screen pixMap
gScreenAddr = StripAddress(GetPixBaseAddr(mainScreenPixMap)); // make non-32bit friendly
gScreenRowBytes = (long)(0x7FFF&(**mainScreenPixMap).rowBytes); // calc screen's rowBytes
/* MAKE A GIANT WINDOW TO COVER ENTIRE SCREEN */
screenRect = qd.screenBits.bounds; // get screen's RECT
bigWindow = NewCWindow(nil,&screenRect,nil,true,
plainDBox,(WindowPtr)-1L,false,0L);
}
/**************** INIT DRAW BUFFER ***************/
//
// Creates an offscreen draw buffer which we will
// be blitting to the main screen.
// The buffer is 640x480 8 bit pixels.
//
static void InitDrawBuffer(void)
{
gDrawBufferPtr = NewPtr(640*480); // allocate the buffer
}
/************************************************************/
/******************** PROGRAM MAIN ENTRY *******************/
/************************************************************/
//
// WARNING: Make sure your monitor is set to 256 colors before
// running this! Bad things may happen otherwise!
//
void main(void)
{
/* DO SETUP STUFF */
ToolBoxInit();
InitScreen();
InitDrawBuffer();
/* PROFILE IT */
ProfileIt();
ShowMenuBar(); // restore menu bar
ExitToShell(); // bye, bye!
}